package com.jingjiu.homeservicesbiz.controller;

import java.util.List;

import com.jingjiu.homeservicesapi.domain.MessageBoard;
import com.jingjiu.homeservicesbiz.service.IMessageBoardService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 留言板：记录用户的留言信息Controller
 * 
 * @author ruoyi
 * @date 2025-04-16
 */
@Controller
@RequestMapping("/system/board")
public class MessageBoardController extends BaseController
{

    @Autowired
    private IMessageBoardService messageBoardService;

    /**
     * 查询留言板：记录用户的留言信息列表
     */
    @RequiresPermissions("system:board:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MessageBoard messageBoard)
    {
        startPage();
        List<MessageBoard> list = messageBoardService.selectMessageBoardList(messageBoard);
        return getDataTable(list);
    }

    /**
     * 导出留言板：记录用户的留言信息列表
     */
    @RequiresPermissions("system:board:export")
    @Log(title = "留言板：记录用户的留言信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(@RequestBody MessageBoard messageBoard)
    {
        List<MessageBoard> list = messageBoardService.selectMessageBoardList(messageBoard);
        ExcelUtil<MessageBoard> util = new ExcelUtil<MessageBoard>(MessageBoard.class);
        return util.exportExcel(list, "留言板：记录用户的留言信息数据");
    }


    /**
     * 新增保存留言板：记录用户的留言信息
     */
    @RequiresPermissions("system:board:add")
    @Log(title = "留言板：记录用户的留言信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@RequestBody MessageBoard messageBoard)
    {
        return toAjax(messageBoardService.insertMessageBoard(messageBoard));
    }

    /**
     * 修改留言板：记录用户的留言信息
     */
    @RequiresPermissions("system:board:edit")
    @GetMapping("/edit/{id}")
    public MessageBoard edit(@PathVariable("id") Long id)
    {
        MessageBoard messageBoard = messageBoardService.selectMessageBoardById(id);
        return messageBoard;
    }

    /**
     * 修改保存留言板：记录用户的留言信息
     */
    @RequiresPermissions("system:board:edit")
    @Log(title = "留言板：记录用户的留言信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@RequestBody MessageBoard messageBoard)
    {
        return toAjax(messageBoardService.updateMessageBoard(messageBoard));
    }

    /**
     * 删除留言板：记录用户的留言信息
     */
    @RequiresPermissions("system:board:remove")
    @Log(title = "留言板：记录用户的留言信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(messageBoardService.deleteMessageBoardByIds(ids));
    }
}
